<?php

require_once(dirname(__FILE__) . '/appconf.php');

class Test extends Site {

    function setup() {
        $this->run_modes('test');
        $this->start_mode('test');
        $this->selfurl = '/testxml.php';
        parent::setup();
    }

    function cgiapp_prerun() {

        parent::cgiapp_prerun();
    }

    function action_test() {

        $xmlObj = simplexml_load_file("http://www.fashionguide.com.tw/beauty/Api/TopicMsgInfL_imore_u8.asp?act=20090821&diaxczh=ieqoj");

        if ($xmlObj) {
            foreach ($xmlObj as $value_row) {

                $insert_array = array("num", "topic", "bname", "pnum", "pname", "price", "volume", "fun", "how", "ps", "udate", "niceimg", "imgurl", "topicurl", "brandurl", "resStandard", "resCondition", "amount", "resamount", "resdates", "resdatee", "backvote", "resShowDate", "item1amount", "item2amount", "item3amount", "item4amount", "item5amount", "item1grade", "item2grade", "item3grade", "item4grade", "item5grade", "item1apercent", "item2apercent", "item3apercent", "item4apercent", "item5apercent", "vote_option_json");

                $insert = array();
                foreach ($insert_array as $insert_value) {
                    
                    $insert[$insert_value] = $this->xml2Str($value_row->$insert_value);
                }

                
                db_add('fg_product', $insert);
                echo $value_row->num . "<br>";
            }
        }
    }

    function xml2Str($obj) {
        return trim((string) $obj);
    }

}

header("Content-type: text/html; charset=utf-8");
$webapp = new Test();
$webapp->run();
?>